package com.kevin.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ExcelUtilTest {

    public static void main(String[] args) {
        ArrayList<Student> data = new ArrayList<>();
        Student student = new Student();
        student.setName("tom");
        student.setAge(19);
        // 在表格中1会变成男
        student.setSex("1");
        student.setBirthday(new Date());
        data.add(student);

        // 需要导出字段的名称
        List<String> fieldsName = new ArrayList<>();
        fieldsName.add("name");
        fieldsName.add("sex");

        ExcelUtil<Student> util = new ExcelUtil<>(Student.class);
        util.exportExcel(data, fieldsName, "人员信息表");
    }
}

class Student {

    @Excel(name = "姓名")
    private String name;

    @Excel(name = "年龄")
    private Integer age;

    @Excel(name = "出生日期", dateFormat = "yyyy-MM-dd")
    private Date birthday;

    @Excel(name = "性别", dictKey = "sex", dictExp = "1=男,2=女")
    private String sex;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }
}